<!--edit by kim-->
<form method="POST" action="index.php?app=b2c&ctl=admin_operator_member&act=add" class="tableform" id="newmember-edit-form">
<div class="tableform">
	<div class="division">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" >
			<tbody>
				<tr><th><em class="red">*</em><{t}>用户名：<{/t}></th><td><{input type="text" name="pam_account[login_name]"  onchange="nameCheck(this)" size="20" vtype="required&&email" placeholder=$__b2c="此处请填写邮箱"|t:'b2c'}><span></span></td></tr>
				<tr><th><em class="red">*</em><{t}>密码：<{/t}></th><td><{input type="password" name="pam_account[login_password]" size="20" vtype="required"}></td></tr>
				<tr><th><em class="red">*</em><{t}>确认密码：<{/t}></th><td><{input type="password" name="pam_account[psw_confirm]" size="20" vtype="required"}></td></tr>
				<tr><th><em class="red">*</em><{t}>会员等级：<{/t}></th><td><{input type='select' name="member_lv[member_group_id]" vtype="required" options=$mem.lv.options value=$business.business }></td></tr>
			</tbody>
		</table>
	</div>
	<div class="division">
		<table>
			<tbody>
				<tr>
					<th><em class="c-red">*</em><{t}>用户姓名：<{/t}></th>
					<td><{input type="text" name="operator[name]" size="20" style="width:200px" vtype="required"}></td>
				</tr>
				<{if $phones}>
				<tr>
					<th><em class="c-red">*</em><{t}>手机区号：<{/t}></th>
					<td>
						<select name="operator[phone_setting]" id="quhao" onchange="checkPerfix(this)">
							<{foreach from=$phones item=items}>
							<option sid="<{$items.length}>" value="<{$items.area}>"><{$items.country}><{$items.area}></option>
							<{/foreach}>
						</select>
					</td>
				</tr>
				<{/if}>
				<tr>
					<th><em class="c-red">*</em><{t}>电话：<{/t}></th>
					<td><{input type="text" name="operator[tel]"  id="mobile" style="width:200px" size="20" vtype="required" onchange="telCheck(this)"}><span></span></td>
				</tr>
				<tr>
					<th><{t}>微信：<{/t}></th>
					<td><{input type="text" name="operator[wx_name]" size="20" style="width:200px"}></td>
				</tr>
				<tr>
					<th><em class="c-red">*</em><{t}>所在地区：<{/t}></th>
					<td>
					<{input app=ectools type="region"  name="operator[company_area]" vtype='area'}><span class="field_notice"></span>
					</td>
				</tr>
				<tr>
					<th>&nbsp;&nbsp;&nbsp;&nbsp; </th>
					<td>
					<{input  type="text"  name="operator[company_addr]" size="20" style="width:200px"}></span>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
</form>
<{area inject='.mainFoot'}>
     <div class="table-action">
	<{button type="button" label=$___b2c="保存"|t:'b2c' id="newmember-edit-form-submit"}>
</div>
<{/area}>
<script>
(function(){
	var _form = $('newmember-edit-form');
	var btn =$('newmember-edit-form-submit');
	var finder = finderGroup['<{$env.get.finder_id}>'];

	_form.store('target',{
		onComplete:function(){            

		},
		onSuccess:function(response){
			var hash_res_obj = JSON.decode(response);
			if (hash_res_obj.success != undefined && hash_res_obj.success != "")
			{
				try{
					var _dialogIns = btn.getParent('.dialog').retrieve('instance');
				}catch(e){}

				if(_dialogIns)
				{
					_dialogIns.close();
					finder.refresh.delay(400,finder);
				}
			}
			else
			{
				//alert(hash_res_obj.error);
			}            
		}
	});

	btn.addEvent('click',function(){
		_form.fireEvent('submit',{stop:$empty});



	});

})();

function nameCheck(input){
	new Request({
		url:'<{link app=b2c ctl=admin_member act=namecheck_email}>',
		method:'post',
		data:input.name+'='+encodeURIComponent(input.value=input.value.trim()),
		onSuccess: function(rs) {
			rs = JSON.decode(rs);
			if(rs.error) {
				input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
			}
			else if(rs.success) {
				input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>';
			}
		}
	}).send();
}

function telCheck(input){
	var obj = $$("#quhao option:selected");
	var phone_setting = '';
	var len = '';
	if(obj && obj[0])
	{
		phone_setting = obj[0].value.replace("+","%2B");
		len = obj[0].get('sid');
	}

	new Request({
		url:'<{link app=b2c ctl=admin_operator_member act=check_tel}>',
		method:'post',
		data:'mobile='+input.value.trim()+"&phone_setting="+phone_setting+'&len='+len,
		onSuccess: function(rs) {
			rs = JSON.decode(rs);
			if(rs.error) {
				input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
			}
			else if(rs.success) {
				input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>';
			}
		}
	}).send();
}

function checkPerfix(obj){
	var phone_setting = obj.get('value');
	var input = $('mobile');
	var mobile = input.get('value');
	var o = $$("#quhao option:selected");
	if(o && o[0])
	{
		var len = o[0].get('sid');
	}
	new Request({
		url:'<{link app=b2c ctl=admin_operator_member act=check_tel}>',
		method:'post',
		data:'mobile='+mobile+"&phone_setting="+phone_setting+'&len='+len,
		onSuccess: function(rs) {
			rs = JSON.decode(rs);
			if(rs.error) {
				input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
			}
			else if(rs.success) {
				input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>';
			}
		}
	}).send();
}
</script>